package com.dingwen.stusprbooes.controller;

import com.dingwen.stusprbooes.constant.ElasticsearchConstant;
import com.dingwen.stusprbooes.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * index
 * @author  dingwen
 * 2021/6/27 21:12
 **/
@RestController
@RequestMapping("/index")
public class IndexController {

    private final IndexService elasticsearchService;

    @Autowired
    public IndexController(IndexService elasticsearchService) {
        this.elasticsearchService = elasticsearchService;
    }

    /**
     * 创建索引
     * //TODO 统一封装返回结果
     *
     * @return {@link Object}
     */
    @PostMapping("")
    public Object create(){
        try {
            return elasticsearchService.createIndex(ElasticsearchConstant.INDEX);
        } catch (IOException e) {
            e.printStackTrace();
            //TODO
        }
        return null;
    }
}
